package com.timothy.shiro;

import java.io.Serializable;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.timothy.business.service.UserService;
import com.timothy.remote.core.PermissionContext;
import com.timothy.remote.core.RemoteServiceInterface;

@Service
public class ServerRmoteService implements RemoteServiceInterface {

	@Autowired
	private UserService userService;
	@Autowired
	private SessionDAO sessionDAO;

	@Override
	public Session getSession(Serializable sessionId) {
		return sessionDAO.readSession(sessionId);
	}

	@Override
	public Serializable createSession(Session session) {
		return sessionDAO.create(session);
	}

	@Override
	public void updateSession(Session session) {
		sessionDAO.update(session);
	}

	@Override
	public void deleteSession(Session session) {
		sessionDAO.delete(session);
	}

	@Override
	public PermissionContext getPermissions(String username) {
		PermissionContext permissionContext = new PermissionContext();
		permissionContext.setPermissions(userService.getUserPermissionsByName(username));
		return permissionContext;
	}
}
